import wyrequest from "@/utils/request"

// --------------------------------分类主页----------------------------
interface categoryGroupArr {
    id: number | string,
    name: string,
}
interface categoryL1ListArr {
    id: number | string,
    superCategoryId: number,
    showIndex: number,
    name: string,
    frontName: null
}
interface ExtraObject {
    crmUserGroupId: string
    crmUserGroupName: string
    itemFrom: number
    materialContentFrom: number
    materialId: string
    materialName: string
    materialType: string
    rcmdSort: boolean
    resourcesId: number
    taskId: string
    taskType: number
}

interface bannerModel {
    id: number,
    picUrl: string,
    targetUrl: string,
    extra: extraModel
}

export interface extraModel {
    materialContentFrom?: number,
    materialName?: string,
    rcmdSort?: boolean,
    taskType?: number,
    itemFrom?: number,
    crmUserGroupName?: string,
    resourcesId?: number,
    materialType?: string,
    crmUserGroupId?: string,
    materialId?: string,
    taskId?: string
}

interface categoryL2ListArr {
    bannerList: bannerModel[],
    bannerUrl: string
    categoryType: number
    extra: ExtraObject
    frontDesc: null
    frontName: string
    frontNameIcon: null
    iconUrl: null
    id: number | string
    imgUrl: null
    level: null
    name: string
    showIndex: number
    subCateList: []
    superCategoryId: []
    type: number
    wapBannerUrl: string
    wapExpandPicTargetUrl: null
}
export interface CategoryModel {
    categoryGroupList: categoryGroupArr[]
    categoryL1List: categoryL1ListArr[]
    categoryL2List: categoryL2ListArr[]
}



// -------------------------搜索商品-------------------------------
export interface resourceOBjj {
    materialName: string
    resourcesId: number
    materialId: number
}
export interface resourceObj {
    resource: resourceOBjj
}

export interface defaultKeywordArr {
    keyword: string,
    schemeUrl: string,
    highlight: number,
    hidden: number,
    type: number,
    algSort: boolean,
    extra: resourceObj
}
export interface resourceStr {
    materialName: string,
    resourcesId: number,
    materialId: number
}

export interface extraStr {
    resource: resourceStr
}
export interface defaultKeywordsArr {
    keyword: string
    schemeUrl: string,
    highlight: number,
    hidden: number,
    type: number,
    algSort: boolean,
    extra: extraStr
}
export interface extraStr {
    materialContentFrom: number,
    rcmdSort: false,
    taskType: number,
    alg_personalized: string,
    itemFrom: number,
    resourcesId: number
}
export interface hotKeywordVOListArr {
    keyword: string,
    schemeUrl: null,
    highlight: number,
    hidden: number,
    type: number,
    algSort: false,
    extra: extraStr
}
export interface searchArr {
    defaultKeyword: defaultKeywordArr,
    defaultKeywords: defaultKeywordsArr[],
    hotKeywordVOList: hotKeywordVOListArr[],
    colorfulEggList: []
}


// -------------------------------商品列表-------------------------





export default {
    // 分类主页
    getNavList(__timestamp: number, categoryId: number | string) {
        return wyrequest.get<any, CategoryModel>(`item/cateList.json?__timestamp=${__timestamp}&categoryId=${categoryId}`)
    },

    // 搜索商品
    getSearch() {
        return wyrequest.get<any, searchArr>(`xhr/search/init.json`)
    },

    // 搜索关键字列表
    findKeyList(inputKeyword: string) {
        return wyrequest({
            url: `xhr/search/searchAutoComplete.json`,
            method: 'POST',
            data: { keywordPrefix: inputKeyword },
            headers: {
                "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
        })
    },

    // 商品列表
    findList(__timestamp:number,categoryType: number,subCategoryId:number, categoryId: number) {
        return wyrequest.get(`item/list.json?__timestamp=${__timestamp}&categoryType=${categoryType}&subCategoryId=${subCategoryId}&categoryId=${categoryId}`)
        
    }

}